#ifndef TICKET_P_H
#define TICKET_P_H

#include "ticket.h"

class QDateTime;
class TicketExplorer;
class TicketExplorerBackendContext;

class TicketPrivate : public Ticket
{
    Q_OBJECT
public:
    TicketPrivate(TicketExplorerBackendContext *ctx);
    TicketPrivate(const TicketPrivate &other);
    virtual ~TicketPrivate();

    int id() const;
    void setId(int id);

    void refresh();

    QDateTime created() const;
    QDateTime modified() const;

    QVariant fieldByName(const QString &fieldName) const;
    bool containsField(const QString &fieldName) const;
    QStringList fieldNames() const;
    QVariantMap fields() const;

    void loadHistory();
    void loadAvailableActions();

    QList<TicketChangeset *> history() const;
    QList<TicketAction *> availableActions() const;

    TicketEditor *editor();

    void setHistory(QList<TicketChangeset *> history);
    void setAvailableActions(QList<TicketAction *> actions);

    void clearChangesets();
    void clearActions();

    Ticket *dup();

    void doUpdateNotify();

protected:
    void save(const QString &comment);

    int m_id;

    QDateTime m_created;
    QDateTime m_modified;

    QMap<QString, QVariant> m_fields;
    QList<TicketChangeset *> m_changesets;
    QList<TicketAction *> m_actions;

    TicketExplorerBackendContext *m_context;

    friend class TicketEditorPrivate;
};

class TicketAction;

class TicketEditorPrivate : public TicketEditor {
public:
    TicketEditorPrivate();
    TicketEditorPrivate(Ticket *ticket);
    ~TicketEditorPrivate();

    void setId(int id) ;
    void setCreated(QDateTime created);
    void setModified(QDateTime modified);
    void setFieldByName(const QString &fieldName, const QVariant &value);

    void save(const QString &comment = "");
    void update();
private:
    void copyTicketDetails(const TicketPrivate * const src, TicketPrivate *dest);

    TicketPrivate *m_ticket;
    TicketPrivate *m_temp;
};





#endif // TICKET_P_H
